package org.come.Frame;

import com.tool.btn.MyAWTEventListener;
import com.tool.image.ImageMixDeal;
import com.updateNew.MyIsif;
import com.updateNew.MyQdModeJFrame;
import org.come.Jpanel.GameJpanel;
import org.come.bean.RoleShow;
import org.come.socket.GameClient;
import org.come.test.Main;
import org.come.until.ScrenceUntil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.MemoryImageSource;

public class GameJframe extends JFrame {
	private String singletitle;
	public static String string=null;
	// 移除线程相关变量

	public GameJframe() throws Exception {
		String a = MyIsif.ifs;
		Image image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(0, 0, new int[0], 0, 0));
		this.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0), null));
		Toolkit tool = this.getToolkit();
		Image myimage = tool.getImage("img/icon/ico.png");
		this.setIconImage(myimage);
		//多开变单开
		// =========================内置多开=====================================================================================
		if (a.equals("D")) {
			GameJframe.this.setTitle("大话西游Ⅱ经典版" + " " +GameClient.BT + " - " + ImageMixDeal.userimg.getRoleShow().getRolename() + " -（ID:" + ImageMixDeal.userimg.getRoleShow().getRole_id() + "）" + "["+ ImageMixDeal.userimg.getRoleShow().getSpecies_id()+"]");
			this.setSize(ScrenceUntil.Screen_x + ScrenceUntil.ChatFram_X + 6, ScrenceUntil.Screen_y + 30);
		} else {
			this.setTitle("大话西游Ⅱ经典版" + Main.index + Main.name.toString());
			setUndecorated(true);
//			// 优化：增加标志位，避免重复创建线程
//			startLocationThreadIfNeeded();
			this.setSize(ScrenceUntil.Screen_x + ScrenceUntil.ChatFram_X, ScrenceUntil.Screen_y);
		}
		// ==============================================================================================================
		this.setContentPane(GameJpanel.getGameJpanel());
		this.pack();
		this.setDefaultCloseOperation(3);
		this.setVisible(true);
		//设置不可以缩放
		this.setResizable(false);
		this.setFocusable(true);
		this.setLocationRelativeTo(null);
		this.setFocusTraversalKeysEnabled(false);
		Toolkit tk = Toolkit.getDefaultToolkit();
		tk.addAWTEventListener(new MyAWTEventListener(), 8L);
		this.addWindowListener(new WindowListener() {
			@Override
			public void windowOpened(WindowEvent e) {
			}

			@Override
			public void windowClosing(WindowEvent e) {

			}

			@Override
			public void windowClosed(WindowEvent e) {

			}

			@Override
			public void windowIconified(WindowEvent e) {
				//     TestMain.chatBoxJframe.setExtendedState(JFrame.ICONIFIED);
			}

			@Override
			public void windowDeiconified(WindowEvent e) {
				//         TestMain.chatBoxJframe.setExtendedState(JFrame.NORMAL);
				//       TestMain.chatBoxJframe.setAlwaysOnTop(true);
				//      TestMain.chatBoxJframe.setAlwaysOnTop(false);
//                ZhuFrame.getZhuJpanel().addPrompt("销毁");
			}

			@Override
			public void windowActivated(WindowEvent e) {
				//   if (TestMain.chatBoxJframe.isAlwaysOnTop()) return;
				//   TestMain.chatBoxJframe.setAlwaysOnTop(true);
				//  TestMain.chatBoxJframe.setAlwaysOnTop(false);
//                ZhuFrame.getZhuJpanel().addPrompt("激活");
			}

			@Override
			public void windowDeactivated(WindowEvent e) {

			}
		});

//        if (!MyIsif.ifs.equals("D"))
//            setLocation(5, 60);
//        else  setLocation(410, 80);//进游戏xy坐标
	}

	// 添加线程控制标志
	private static boolean locationThreadStarted = false;
	private static Thread locationThread = null;

	// 优化位置设置线程，添加同步控制
	// 简化位置设置方法，只设置一次初始位置
//	private void startLocationThreadIfNeeded() {
//		// 设置初始位置
//		setLocation(5, 60);
//		// 不再启动任何位置调整线程
//	}
}
